package com.hkfn.rfb.common.bean;

import android.content.Context;

import com.hkfn.rfb.common.utils.JSONUtil;
import com.hkfn.rfb.common.utils.PreferencesUtils;
import com.hkfn.rfb.common.utils.StringUtils;

public class UserInfoModel extends BaseModel {

    private String id;
    private String realName;
    private String avatar;
    private String token;
    private String phone;
    private String email;
    private String sex;
    private String deptId;
    private String roleId;
    private String account;

    private boolean isSelect = false;
    private boolean canDelete = false;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getDeptId() {
        return deptId;
    }

    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }

    public boolean isSelect() {
        return isSelect;
    }

    public void setSelect(boolean select) {
        isSelect = select;
    }

    public boolean isCanDelete() {
        return canDelete;
    }

    public void setCanDelete(boolean canDelete) {
        this.canDelete = canDelete;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getRoleId() {
        return roleId;
    }

    public void setRoleId(String roleId) {
        this.roleId = roleId;
    }

    public UserInfoModel() {
    }

    /**
     * 获取用户账号
     * @param context
     * @return
     */
    public static String getUserAccount(Context context){
        return PreferencesUtils.getString(context, ConstData.USERACCOUNT, "");
    }

    /**
     * 设置用户账号
     * @param context
     * @return
     */
    public static boolean setUserAccount(Context context, String userAccount){
        return PreferencesUtils.putString(context, ConstData.USERACCOUNT, userAccount);
    }

    /**
     * 获取用户密码
     * @param context
     * @return
     */
    public static String getUserPassword(Context context){
        return PreferencesUtils.getString(context, ConstData.USERPASSWORD, "");
    }

    /**
     * 设置用户密码
     * @param context
     * @return
     */
    public static boolean setUserPassword(Context context, String password){
        return PreferencesUtils.putString(context, ConstData.USERPASSWORD, password);
    }

    public static String getUserToken(Context context) {
        return PreferencesUtils.getString(context, ConstData.USERTOKEN, "");
    }

    /**
     *
     * @param context
     * @return
     */
    public static boolean setUserToken(Context context, String userToken){
        return PreferencesUtils.putString(context, ConstData.USERTOKEN, userToken);
    }

    public static String getUserRole(Context context) {
        return PreferencesUtils.getString(context, ConstData.USERROLE, "");
    }

    /**
     *  用户权限
     * @param context
     * @return
     */
    public static boolean setUserRole(Context context, String userToken){
        return PreferencesUtils.putString(context, ConstData.USERROLE, userToken);
    }

    /**
     * 获取用户信息
     * @param context
     * @return
     */
    public static UserInfoModel getUserInfo(Context context){
        UserInfoModel userInfoModel = null;
        userInfoModel = JSONUtil.jsonObjectToBean(PreferencesUtils.getString(context, ConstData.USERINFO, ""), UserInfoModel.class);
        return userInfoModel;
    }

    /**
     * 获取公司id
     */
    public static String getCompandId(Context context){
        return PreferencesUtils.getString(context, ConstData.COMPANYID, "");
    }

    /**
     * 设置公司id
     * @param context
     */
    public static void setCompandId(Context context, String companyId){
        PreferencesUtils.putString(context, ConstData.COMPANYID, companyId);
    }

    /**
     * 判断用户是否登录
     * @param context
     * @return
     */
    public static boolean isLogin(Context context){
        return !StringUtils.isEmpty(getUserToken(context));
    }

    /**
     * 清除用户信息
     * @param context
     */
    public static void clearUserLoginMessage(Context context){
        UserInfoModel.setCompandId(context, "");
        PreferencesUtils.putString(context, ConstData.USERINFO, "");
        UserInfoModel.setUserToken(context, "");
    }
}
